<?php
/**
 * @author 	 	 faithsmine@gmail.com
 * @copyright            www
 * @version              1.0
 * @name 		 loginadmin.php
 * @todo 		 用户 登录/ 退出
 * @final 		 2009-12-10
 */
define('IN_YCTOOL', true);//定义该文件合法性
require_once('config.php');
require_once(DIR_COMM . 'common.php');
$emvalue	= isset($_POST['emvalue']) ? $_POST['emvalue'] : '';
$action		= isset($_GET['action']) ? $_GET['action'] : '';
$userpass	= isset($_POST['userpass']) ? $_POST['userpass'] : '';
$cookie		= isset($_POST['cookie']) ? $_POST['cookie'] : 0;

$url = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] :'./admin/';
substr( basename($url) , 0 , 14) == 'loginadmin.php' && $url = './admin/';

if ($action == 'logout')
{
    $user->logout();
    func::obHeader('./');
    exit();
}

if ($user->userinfo['userid'] > 0)
{
    func::obHeader($url);
    exit();
}

if ($emvalue && $userpass)
{
    $ret = $user->login($emvalue, $userpass, $cookie);
    switch ($ret)
    {
	case "USER_LOGIN_SUCCESS":
	    $user->updateLogin($user->userinfo['userid']);
	    func::obHeader($url);
	    break;
	case "USER_PASSWORD_ERROR":
	    func::showMsg("用户密码不正确", './');
	    break;
	case "USER_NOT_EXIST":
	    func::showMsg("此用户不存在", './');
	    break;
	default:;
    }
    exit();
}

require_once DIR_COMM.'template.func.php';
require_once tpl('logintherul.html', $tpldir);
?>
